package com.example.project.dao;

import com.example.project.entity.Activity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ActivityDAO extends JpaRepository<Activity,String>, JpaSpecificationExecutor<Activity> {

    @Modifying
    @Query(nativeQuery = true, value = "UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = ?")
    int deleteActivityByState(String activityId);

    Activity findOneById(String activityId);

    Page<Activity> findAll(Pageable pageable);

    //分页列出案例
    @Query(value = " select * from tb_activity a where  a.state = '2'",nativeQuery = true)
    List<Activity> findByState(Pageable pageable);

    Page<Activity> findAllByAuthor(String author ,Pageable pageable);


}
